import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    isCollapse: false,//侧边栏默认是打开状态
    isHidden:true,//Logo默认是大图

    /*用户信息*/
    //给userInfo赋初始值，是为了避免刷新页面，state变为空
    userInfo:JSON.parse(sessionStorage.getItem("userInfo")),

    /*tab选项卡*/
    /** 当前tab的路径   '/menu/main' 可以更改为自己默认的页面*/
    editableTabsValue:'/menu/main',
    /*tab数组*/
    editableTabs: [{title:'首页',name:'/menu/main'}],

    /*会员编辑页面*/
    dialogVip:false,

    theme:'chalk',
  },
  getters:{
    getCollapse:state => {
      return state.isCollapse;
    },
    getHidden:state => {
      return state.isHidden;
    },

    /*tab选项卡*/
    editableTabsValue:state => state.editableTabsValue,
    editableTabs:state => state.editableTabs,

    /*编辑页面*/
    dialogVip:state => state.dialogVip,

    /*用户操作*/
    getUserInfo:state => {
      return state.userInfo;
    }
  },
  mutations: {
    setCollapse(state){
      if (state.isCollapse) {
        state.isCollapse=false;
        state.isHidden=true;
        //alert("改为false")
      }else {
        state.isCollapse=true;
        state.isHidden=false;
        //alert("改为true")
      }
    },

    /*tab选项卡*/
    //设置当前tab数组
    addTab(state,data){
      state.editableTabs = data;
      //Auth.setEditableTabs(data);
    },
    //设置当前tab
    setTabName(state,data){
      state.editableTabsValue = data;
      //Auth.setEditableTabsValue(data);
    },

    /*编辑面板*/
    setDialog(state,data){
      state.dialogVip = data;
    },

    /*echart主题切换*/
    changeTheme(state){
      if (state.theme === 'chalk') {
        state.theme='vintage'
      }else {
        state.theme='chalk'
      }
    },

    /*登录操作*/
    SET_USERINFO:(state,userInfo)=>{
      state.userInfo=userInfo;
      sessionStorage.setItem("userInfo",JSON.stringify(userInfo));
    },
    REMOVE_USERINFO:state => {
      state.userInfo={};
      sessionStorage.removeItem("userInfo");
    }

  },
  actions: {
  },
  modules: {
  }
})
